<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>我的订单</p>
    </header>

    <!-- 订单列表部分 -->
    <div class="order-section">
      <h3>未支付订单：</h3>
      <ul class="order">
        <li v-for="(order, index) in unpaidOrders" :key="'unpaid-'+index">
          <div class="order-info">
            <p>
              {{ order.shopName }}
              <i class="fa fa-caret-down" @click="toggleOrderDetail(order)"></i>
            </p>
            <div class="order-info-right">
              <p>￥{{ order.totalPrice }}</p>
              <div class="order-info-right-icon" @click="goToPayment">去支付</div>
            </div>
          </div>
          <ul class="order-detailet" v-show="order.showDetail">
            <li v-for="(item, itemIndex) in order.items" :key="itemIndex">
              <p>{{ item.name }} x {{ item.quantity }}</p>
              <p>￥{{ item.price }}</p>
            </li>
            <li>
              <p>配送费</p>
              <p>￥{{ order.deliveryFee }}</p>
            </li>
          </ul>
        </li>
      </ul>

      <h3>已支付订单：</h3>
      <ul class="order">
        <li v-for="(order, index) in paidOrders" :key="'paid-'+index">
          <div class="order-info">
            <p>
              {{ order.shopName }}
              <i class="fa fa-caret-down" @click="toggleOrderDetail(order)"></i>
            </p>
            <div class="order-info-right">
              <p>￥{{ order.totalPrice }}</p>
              <div class="status-paid">已支付</div>
            </div>
          </div>
          <ul class="order-detailet" v-show="order.showDetail">
            <li v-for="(item, itemIndex) in order.items" :key="itemIndex">
              <p>{{ item.name }} x {{ item.quantity }}</p>
              <p>￥{{ item.price }}</p>
            </li>
            <li>
              <p>配送费</p>
              <p>￥{{ order.deliveryFee }}</p>
            </li>
          </ul>
        </li>
      </ul>
    </div>

    <div class="pb-16vw"></div>
    <Footer />
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { useRouter } from 'vue-router'
import Footer from '../components/Footer.vue'

export default defineComponent({
  name: 'OrderList',
  components: {
    Footer
  },
  setup() {
    const router = useRouter()
    const unpaidOrders = ref([
      {
        shopName: '万家饺子（驼峰街店）',
        totalPrice: 49,
        deliveryFee: 3,
        showDetail: false,
        items: [
          { name: '纯肉鲜肉（水饺）', quantity: 2, price: 15 },
          { name: '玉米鲜肉（水饺）', quantity: 1, price: 16 }
        ]
      },
      {
        shopName: '小锅饭豆腐馆（云南大学店）',
        totalPrice: 55,
        deliveryFee: 3,
        showDetail: false,
        items: [
          { name: '纯肉鲜肉（水饺）', quantity: 2, price: 15 },
          { name: '玉米鲜肉（水饺）', quantity: 1, price: 16 }
        ]
      }
    ])

    const paidOrders = ref([
      {
        shopName: '万家饺子（驼峰街店）',
        totalPrice: 49,
        deliveryFee: 3,
        showDetail: false,
        items: [
          { name: '纯肉鲜肉（水饺）', quantity: 2, price: 15 },
          { name: '玉米鲜肉（水饺）', quantity: 1, price: 16 }
        ]
      },
      {
        shopName: '小锅饭豆腐馆（云南大学店）',
        totalPrice: 55,
        deliveryFee: 3,
        showDetail: false,
        items: [
          { name: '纯肉鲜肉（水饺）', quantity: 2, price: 15 },
          { name: '玉米鲜肉（水饺）', quantity: 1, price: 16 }
        ]
      }
    ])

    const toggleOrderDetail = (order: any) => {
      order.showDetail = !order.showDetail
    }

    const goToPayment = () => {
      router.push('/payment')
    }

    return {
      unpaidOrders,
      paidOrders,
      toggleOrderDetail,
      goToPayment
    }
  }
})
</script>

<style scoped>
/****************** 总容器 ******************/
.wrapper{
  width: 100%;
  height: 100%;
}

/****************** header部分 ******************/
.wrapper header{
  width: 100%;
  height: 12vw;
  background-color: #0097FF;
  color: #fff;
  font-size: 4.8vw;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

/****************** 订单区域 ******************/
.order-section {
  margin-top: 12vw;
  background-color: #f8f8f8;
  min-height: calc(100vh - 12vw);
}

/****************** 历史订单列表部分 ******************/
.wrapper h3{
  margin: 0;
  box-sizing: border-box;
  padding: 4vw;
  font-size: 4vw;
  font-weight: 400;
  color: #666;
  background-color: #f0f0f0;
}

.wrapper .order{
  width: 100%;
  background-color: white;
  margin-bottom: 2vw;
}

.wrapper .order li{
  width: 100%;
  border-bottom: 1px solid #f0f0f0;
}

.wrapper .order li:last-child{
  border-bottom: none;
}

.wrapper .order li .order-info{
  box-sizing: border-box;
  padding: 4vw;
  font-size: 4vw;
  color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: white;
}

.wrapper .order li .order-info p{
  margin: 0;
  font-weight: 500;
}

.wrapper .order li .order-info .order-info-right{
  display: flex;
  align-items: center;
  gap: 3vw;
}

.wrapper .order li .order-info .order-info-right p{
  color: #ff6b35;
  font-weight: 600;
}

.wrapper .order li .order-info .order-info-right-icon{
  background-color: #ff6b35;
  color: #fff;
  border-radius: 4vw;
  padding: 2vw 4vw;
  user-select: none;
  cursor: pointer;
  font-size: 3.2vw;
  transition: background-color 0.3s ease;
}

.wrapper .order li .order-info .order-info-right-icon:active{
  background-color: #e55a2b;
}

.status-paid{
  background-color: #38CA73;
  color: #fff;
  border-radius: 4vw;
  padding: 2vw 4vw;
  font-size: 3.2vw;
}

.wrapper .order-detailet{
  width: 100%;
  background-color: #f9f9f9;
}

.wrapper .order-detailet li{
  width: 100%;
  box-sizing: border-box;
  padding: 2vw 4vw;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
}

.wrapper .order-detailet li:last-child{
  border-bottom: none;
}

.wrapper .order-detailet li p{
  font-size: 3.2vw;
  color: #666;
  margin: 0;
}

.pb-16vw {
  padding-bottom: 16vw;
}
</style> 